package edu.xhu.video.config;

import lombok.Data;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Data
@Configuration
@ConfigurationProperties(prefix = "es")
//@PropertySource(value = {"classpath:application.yml"}, encoding = "utf-8")
public class ElasticsSearchConfig {
    @Value("${elasticsearch.host1}")
    private String host1;
    @Value("${elasticsearch.host2}")
    private String host2;
    @Value("${elasticsearch.port}")
    private int port;

    @Bean(value = "restHighLevelClient")
    public RestHighLevelClient client() {
        //        return new RestHighLevelClient(RestClient.builder(new HttpHost(host1, port), new HttpHost(host2, port)));
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(
                new HttpHost(host1, port)
        ));
        return client;
    }
}
